window.onload = function () {

    var seckill ={
        init:function(){
            this.endTime = new Date("2018-11-23 21:30:10");
        },
        endTime:null,
        seckill:function () {
            //获取当前时间
            var nowTime = new Date();
    
            //获取剩余毫秒数
            var interval
                = seckill.endTime.getTime() - nowTime.getTime();
            //在少于1秒时，清理定时任务
            if(interval <= 999){
                clearInterval(this.timer);
            }
            //剩余天数
            var day
                = Number.parseInt(interval / (24 * 60 * 60 * 1000));
            //剩余的小时
            var hour
                = Number.parseInt((interval - day * (24 * 60 * 60 * 1000)) / (60 * 60 * 1000));
            //剩余的分钟
            var minute
                = Number.parseInt((interval % (60 * 60 * 1000)) / (60 * 1000))
            //秒
            var second = Number.parseInt((interval % (60 * 1000)) / (1000));
            console.log(day,hour,minute,second);
            //更新界面
            daydiv = document.getElementsByClassName('day')[0];
            daydiv.innerHTML = day + "天";
    
            hourdiv = document.getElementsByClassName('hour')[0];
            hourdiv.innerHTML = hour + "时";
    
            minutediv = document.getElementsByClassName('minute')[0];
            minutediv.innerHTML = minute + "分";
    
            seconddiv = document.getElementsByClassName('second')[0];
            seconddiv.innerHTML = second + "秒";
        },
        timer:null,
        start:function(){
            this.timer = setInterval(this.seckill, 1000);
        }   
    }
    seckill.init();
    seckill.start();

    

    
}